using Microsoft.SqlServer.Management.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace Microsoft.SqlServer.Management.SqlManagerUI
{
	internal class GenScriptFinishWizardPage : WizardPage
	{
		protected string AdvancedCaption = "";

		private TreeView idDescriptionTree;

		private Label idDescriptionLabel;

		protected IContainer components;

		public GenScriptFinishWizardPage(WizardForm wizard) : base(wizard)
		{
			this.InitializeComponent();
			this.LoadStrings();
			base.PageID = 23;
			this.SubTitle = GenScriptWizSR.DescriptionPageSubtitle;
			this.Title = GenScriptWizSR.DescriptionPageTitle;
			base.HelpTopicKeyword = "sql9.swb.generatescriptswizard.scriptwizarddescription.f1";
		}

		private void LoadStrings()
		{
			this.idDescriptionLabel.Text = GenScriptWizSR.DescriptionLabel;
		}

		private void InitializeComponent()
		{
			this.idDescriptionLabel = new Label();
			this.idDescriptionTree = new TreeView();
			base.SuspendLayout();
			this.idDescriptionLabel.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.idDescriptionLabel.Location = new Point(16, 12);
			this.idDescriptionLabel.Name = "idDescriptionLabel";
			this.idDescriptionLabel.Size = new Size(432, 16);
			this.idDescriptionLabel.TabIndex = 0;
			this.idDescriptionLabel.Text = GenScriptWizSR.DescriptionLabel;
			this.idDescriptionTree.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.idDescriptionTree.ImageIndex = -1;
			this.idDescriptionTree.Location = new Point(16, 36);
			this.idDescriptionTree.Name = "idDescriptionTree";
			this.idDescriptionTree.SelectedImageIndex = -1;
			this.idDescriptionTree.Size = new Size(432, 197);
			this.idDescriptionTree.TabIndex = 1;
			base.Controls.Add(this.idDescriptionTree);
			base.Controls.Add(this.idDescriptionLabel);
			base.Name = "GenScriptDescriptionForm";
			base.Size = new Size(464, 245);
			base.ResumeLayout(false);
		}

		public void FillTree()
		{
			bool finishEnabled = false;
			TreeNode treeNode = new TreeNode();
			bool flag = base.WizardInputs.FindBool(3);
			if (flag)
			{
				finishEnabled = true;
			}
			treeNode.Text = GenScriptWizSR.DescriptionPageDescription;
			GenWizGeneralData genWizGeneralData = (GenWizGeneralData)base.WizardInputs.FindItem(0);
			genWizGeneralData.AddGeneralDescription(treeNode);
			genWizGeneralData.AddOutputDescription(treeNode);
			GenWizOptionsBase genWizOptionsBase = (GenWizOptionsBase)base.WizardInputs.FindItem(1);
			genWizOptionsBase.AddOptionsDesc(treeNode);
			if (!flag)
			{
				List<GenWizObjectType> list = (List<GenWizObjectType>)base.WizardInputs.FindItem(2);
				foreach (GenWizObjectType current in list)
				{
					if (current.IsSelected)
					{
						finishEnabled = true;
					}
				}
			}
			base.FinishEnabled = finishEnabled;
			this.idDescriptionTree.Nodes.Clear();
			foreach (TreeNode treeNode2 in treeNode.Nodes)
			{
				this.idDescriptionTree.Nodes.Add(treeNode2);
				treeNode2.Expand();
			}
			treeNode.Expand();
		}

		protected override void OnLeavePage(LeavePageEventArgs e)
		{
			base.FinishEnabled = false;
			if (e.Button == WizardButton.Finish)
			{
				GenWizGeneralData genWizGeneralData = (GenWizGeneralData)base.WizardInputs.FindItem(0);
				if (genWizGeneralData.SaveScriptDestination == GenWizGeneralData.ScriptDestination.ToProvider)
				{
					if (string.IsNullOrEmpty(genWizGeneralData.Provider.UserName) || string.IsNullOrEmpty(genWizGeneralData.Provider.Password) || string.IsNullOrEmpty(genWizGeneralData.Database.UserName) || string.IsNullOrEmpty(genWizGeneralData.Database.Password))
					{
						new RemoteCreditDialog
						{
							Provider = genWizGeneralData.Provider,
							Database = genWizGeneralData.Database
						}.ShowDialog(this);
					}
					if (string.IsNullOrEmpty(genWizGeneralData.Provider.UserName) || string.IsNullOrEmpty(genWizGeneralData.Provider.Password) || string.IsNullOrEmpty(genWizGeneralData.Database.UserName) || string.IsNullOrEmpty(genWizGeneralData.Database.Password))
					{
						e.Cancel = true;
						base.FinishEnabled = true;
					}
				}
			}
		}

		protected override void OnEnterPage(EventArgs e)
		{
			base.NextEnabled = false;
			this.FillTree();
		}
	}
}
